//
//  WKWebView+Conform.m
//  packetwallet
//
//  Created by 张冬 on 15/10/21.
//  Copyright © 2015年 Hangzhou TaiXuan Network Technology Co., Ltd. All rights reserved.
//

#import "WKWebView+Conform.h"

@implementation WKWebView (Conform)

- (void)scalesPageToFit:(BOOL)isFit {
    return;
}

- (UIView *)baseView {
    return self;
}

- (void)loadReuqestWithString:(NSString *)string {
    SEL selector = NSSelectorFromString(@"loadRequest:");
    if ([self respondsToSelector:selector]) {
        
        [self performSelectorOnMainThread:selector withObject:[NSURLRequest requestWithURL:[NSURL URLWithString:string]] waitUntilDone:YES];
    }
}

- (void)clearCacheIfNeed {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
    if ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f) {
        
        NSSet *websiteDataTypes = [NSSet setWithArray:@[WKWebsiteDataTypeDiskCache]];
        
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:0];
        
        [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:date completionHandler:^{
            
        }];
    }
#endif
}

#pragma mark WKUIDelegate WKNavigationDelegate
- (void)setWebViewDelegate:(id <WKNavigationDelegate, WKUIDelegate>)delegate {
    self.navigationDelegate = delegate;
    self.UIDelegate = delegate;
}

@end
